home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / elecmail / fido1000.zip / SRC1000.ZIP / FIDOMSG.C < prev    next >
Text File  |  1993-05-21  |  6KB  |  225 lines

  1. /* file to place the FTSC message processing functions in */
  2.  
  3. #include    "ftsc.h"
  4. #include    "gt16.h"
  5. #include    "datemath.h"
  6. #include    <bios.h>
  7. #include    <conio.h>
  8. #include    <dos.h>
  9. #include    <process.h>
  10. #include    <stdio.h>
  11. #include    <stdlib.h>
  12. #include    <string.h>
  13. #include    <time.h>
  14.  
  15. extern ADDRTYPE myaddress;
  16.  
  17. /*----------------------------------------------------------------------*/
  18. int ftsc_addrset(FIDOHEADER *hdr, char *mbuf,ADDRTYPE *t_addr)
  19. {
  20.     char *tptr;
  21.  
  22.     tptr = strstr(mbuf,"MSGID:");
  23.     if (tptr == NULL)
  24.     {
  25.         t_addr->zone = myaddress.zone;
  26.     }
  27.     else
  28.     {
  29.         t_addr->zone = 0;
  30.         sscanf(tptr+7,"%d",&t_addr->zone);
  31.     }
  32.  
  33.     tptr = strstr(mbuf,"FMPT");
  34.     if (tptr == NULL)
  35.     {
  36.         t_addr->point = 0;
  37.     }
  38.     else
  39.     {
  40.         t_addr->point = 0;
  41.         sscanf(tptr+5,"%d",&t_addr->point);
  42.     }
  43.         
  44.     t_addr->net = hdr->orig_net;
  45.     t_addr->node = hdr->orig;
  46.  
  47.     return 1;
  48. }
  49.  
  50. /*----------------------------------------------------------------------*/
  51. int ftsc_read(int n, char *mp, FIDOHEADER *hdr, char *mtext)
  52. {
  53.    char   *fn;
  54.    char   tmp[14];
  55.    FILE   *fp;
  56.  
  57.    fn = malloc(80);
  58.    sprintf(tmp,"%d.MSG",n);
  59.    strcpy(fn,mp);
  60.    strcat(fn,tmp);
  61.    if ((fp = fopen(fn,"rb")) == NULL)
  62.    {
  63.       free(fn);
  64.       return(-1);
  65.    }
  66.    fread(hdr,sizeof(FIDOHEADER),1,fp);
  67.  
  68.    fread(mtext,1,MAXMSGSZ,fp);
  69.  
  70.    free(fn);
  71.    fclose(fp);
  72.    return(0);
  73.  
  74. }
  75. /*----------------------------------------------------------------------*/
  76. int ftsc_write(int n, char *mp, FIDOHEADER *hdr, char *mtext)
  77. {
  78.   char *fn;
  79.   char tmp[14];
  80.   FILE *fp;
  81.  
  82.   fn = malloc(80);
  83.   sprintf(tmp,"%d.MSG",n);
  84.   strcpy(fn,mp);
  85.   strcat(fn,tmp);
  86.   if ((fp = fopen(fn,"wb")) == NULL)
  87.   {
  88.      free(fn);
  89.      return(-1);
  90.   }
  91.   fwrite(hdr,sizeof(FIDOHEADER),1,fp);
  92.  
  93.   fclose(fp);
  94.  
  95.   if ((fp = fopen(fn,"at")) == NULL)
  96.   {
  97.      free(fn);
  98.      return(-1);
  99.   }
  100.   fwrite(mtext,1,strlen(mtext)+1,fp); /* +1 is so that NULL byte goes out to */
  101.  
  102.   free(fn);
  103.   fclose(fp);
  104.   return(0);
  105. }
  106. /*----------------------------------------------------------------------*/
  107.  
  108. int ftsc_delete(int n, char *mp)
  109.  
  110. /* n     message number to delete    */
  111. /* *mp   ftsc path to delete it from */
  112.  
  113. {
  114.     char *fn;
  115.     char tmp[14];
  116.  
  117.     fn = malloc(80);
  118.     sprintf(tmp,"%d.MSG",n);
  119.     strcpy(fn,mp);
  120.     strcat(fn,tmp);
  121.     remove(fn);
  122.     free(fn);
  123.     return(0);
  124.  
  125. }
  126.  
  127. /*──────────────────────────────────────────────────────────────────*/
  128.  
  129. int ftsc_append(char *mp, FIDOHEADER *hdr, char *mtext)
  130.  
  131. {
  132.    int  fidohigh,i;
  133.  
  134.    fidohigh = get_ftsc_high(mp);
  135.    fidohigh++;
  136.    if (fidohigh == 1) fidohigh = 2;
  137.    i = ftsc_write(fidohigh,mp,hdr,mtext);
  138.    return(i);
  139. }
  140.  
  141. /* ────────────────────────────────────────────────────────────────── */
  142.  
  143. int get_ftsc_high(char *mp)
  144. {
  145.    char    *fn;                         /* file masking string */
  146.    struct  find_t  fileinfo;
  147.    int     status;                      /* status of last file search */
  148.    int     got;                         /* place to hold current msgnum */
  149.    int     fidohigh;                    /* highest message number       */
  150.  
  151.    fn = malloc(80);
  152.    strcpy(fn,mp);
  153.    strcat(fn,"*.MSG");
  154.  
  155.    fidohigh = 0;
  156.  
  157.    status = _dos_findfirst(fn, _A_NORMAL, &fileinfo);
  158.    while (status == 0)
  159.    {
  160.       sscanf(fileinfo.name,"%d.MSG",&got);
  161.       if (got > fidohigh) fidohigh = got;
  162.       status = _dos_findnext(&fileinfo);
  163.    }
  164.  
  165.    free(fn);
  166.    return(fidohigh);
  167. }
  168. /* ───────────────────────────────────────────────────────────────────── */
  169.  
  170. int prn_ftsc_hdr(FIDOHEADER *fhdr)
  171. {
  172.    printf("\n──────────────────────────────────────────────────────────────");
  173.    printf("\nFrom: %s",fhdr->from);
  174.    printf("\n  To: %s",fhdr->to);
  175.    printf("\nSubj: %s",fhdr->subj);
  176.    printf("\nDate: %s",fhdr->date);
  177.    printf("\n────────── Binary Data Follows ───────────────────────────────");
  178.    printf("\nTimes read: %d  Dest: %d  Orig: %d  Cost: %d",fhdr->times, fhdr->dest, fhdr->orig, fhdr->cost);
  179.    printf("\nOrig Net: %d  Dest Net: %d",fhdr->orig_net, fhdr->dest_net);
  180.    printf("\nDate written: %d/%d/%d",fhdr->written.day, fhdr->written.mon, fhdr->written.year);
  181.    printf("\nDate arrived: %d/%d/%d",fhdr->arrived.day, fhdr->arrived.mon, fhdr->arrived.year);
  182.    printf("\n──────────────────────────────────────────────────────────────\n");
  183.    return(0);
  184. }
  185.  
  186.  
  187. unsigned long msgid_idval(void)
  188. {
  189.     unsigned long       timeval, dateval;
  190.     struct _dostime_t   mtime;
  191.     unsigned int        tempval;
  192.     unsigned long       templong;
  193.  
  194.     _dos_gettime( &mtime );
  195.  
  196.     tempval = eday_today();
  197.     tempval -= 2000;
  198.  
  199.     if (tempval > 4095) tempval -= 4000;    /* should give 20 years of life! */
  200.     if (tempval > 4095) tempval -= 4000;    /* should give 20 years of life! */
  201.     if (tempval > 4095) tempval -= 4000;    /* should give 20 years of life! */
  202.  
  203.     templong = tempval;
  204.     dateval = templong * 1048575L;  /* 0xFFFFF */
  205.  
  206.     templong = (unsigned) mtime.hour;
  207.     timeval = (templong * (60L * 60L));
  208.  
  209.     templong = (unsigned) mtime.minute;
  210.     timeval += (templong * (60L));
  211.  
  212.     templong = (unsigned) mtime.second;
  213.     timeval += (templong);
  214.  
  215.     templong = timeval;
  216.     timeval = templong * 10;
  217.  
  218.     timeval += (unsigned) (mtime.hsecond / 10);
  219.  
  220.     templong = timeval + dateval;
  221.  
  222.     return(templong);
  223. }
  224.     
  225.